#!/bin/sh  
 
# 检查是否提供了ZIP文件名作为参数
if [ -z "$1" ]; then
  echo "Usage: $0 <zip-file-name>"
  exit 1
fi
 
ZIP_FILE="$1"
PARENT_DIR="../"
 
# 检查ZIP文件是否存在
if [ ! -f "$ZIP_FILE" ]; then
  echo "Error: ZIP file '$ZIP_FILE' not found in the current directory."
  exit 1
fi
 
# 复制ZIP文件到上一级目录
cp "$ZIP_FILE" "$PARENT_DIR"
 
# 切换到上一级目录
cd "$PARENT_DIR" || { echo "Failed to change directory to '$PARENT_DIR'"; exit 1; }
 
# 解压ZIP文件并覆盖已有文件
unzip -o "$ZIP_FILE"
 
# 检查unzip命令是否成功
if [ $? -ne 0 ]; then
  echo "Error: Failed to unzip '$ZIP_FILE'."
  exit 1
fi
 
echo "ZIP file '$ZIP_FILE' copied to '$PARENT_DIR' and extracted successfully, overwriting existing files if any."